﻿@model Sheng.Enterprise.Web.RegisterViewModel

@{
    ViewBag.Title = "注册";
    Layout = "~/Views/Shared/_LayoutSimple.cshtml";
}

<script src="~/Scripts/MD5.js" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function ()
    {
        $("#valiCode").bind("click", function ()
        {
            this.src = "/Api/UserContext/GetValidateCode?time=" + (new Date()).getTime();
        });
        
        $("[keyenter]").keypress(function (e)
        {
            if (e.keyCode == 13)
            {
                register();
            }
        });

        heartbeat();
    });

    function register()
    {
        if ($("#formRegister").validate({
            rules: {
                    "txtAccount": {
                        required: true,
                        minlength: 3
                    },
                    "txtPassword": "required",
                    "txtPassword2": {
            required: true,
            minlength: 3,
            equalTo: "#txtPassword"
        },
                    "txtName": "required",
                    "txtDomainName": "required",
                    "txtValidateCode": "required"
        },
            messages: {
                    "txtAccount": "!",
                    "txtPassword": "!",
                    "txtPassword2": {
            required: "!",
            minlength: "密码长度至少 3 位以上",
            equalTo: "两次密码输入不一致"
        },
                    "txtName": "!",
                    "txtDomainName": "!",
                    "txtValidateCode": "!"
        }
        }).form() === false)
        {
            layerInputAlertMsg();
            return;
        }

        var args = new Object();
        args.Account = $("#txtAccount").val();
        args.Password = hex_md5($("#txtPassword").val()).toUpperCase();
        args.Name = $("#txtName").val();
        args.Email = $("#txtEmail").val();
        args.Telphone = $("#txtTelphone").val();
        args.DomainName = $("#txtDomainName").val();
        args.ValidateCode = $("#txtValidateCode").val();

        layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/User/Register",
            type: "POST",
            dataType: "json",
            data: JSON.stringify(args),
            success: function (data, status, jqXHR)
            {
                if (data.Success)
                {
                    //如果成功，不隐藏mask，否则跳转期间页面还可操作

                    window.location.href = "/Home/Introduction";
                } else
                {
                    layer.closeAll();

                    layerAlert(data.Message, function () { $("#txtValidateCode").focus(); });
                }
            },
            error: function (xmlHttpRequest)
            {
                layer.closeAll();
                
                //responseText
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

</script>
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="30">&nbsp;</td>
    </tr>
    <tr>
        <td class="font_black_26">注册</td>
    </tr>
    <tr>
        <td height="30">&nbsp;</td>
    </tr>
    <tr>
        <td bgcolor="#D4D4D4" height="1"></td>
    </tr>
    <tr>
        <td height="40">&nbsp;</td>
    </tr>
    <tr>
        <td>
            <form id="formRegister">
                <table width="680" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="140" height="50">账号：</td>
                        <td><input type="text" maxlength="50" class="input_18" style="width:350px;" id="txtAccount" name="txtAccount" keyenter /></td>
                    </tr>
                    <tr>
                        <td height="30">&nbsp;</td>
                        <td valign="top">
                            <span class="font_gray_15" style="">3位以上，推荐使用电子邮件地址或手机号码等唯一性较强的标识作为帐户</span>
                        </td>
                    </tr>
                    <tr>
                        <td height="50">密码：</td>
                        <td><input type="password" maxlength="25" class="input_18" style="width:350px;" id="txtPassword" name="txtPassword" keyenter /></td>
                    </tr>
                    <tr>
                        <td height="50">再次输入密码：</td>
                        <td><input type="password" maxlength="25" class="input_18" style="width:350px;" id="txtPassword2" name="txtPassword2" keyenter /></td>
                    </tr>
                    <tr>
                        <td height="30">&nbsp;</td>
                        <td valign="top">
                            <span class="font_gray_15" style="">密码至少3位以上</span>
                        </td>
                    </tr>
                    <tr>
                        <td height="50">姓名：</td>
                        <td><input type="text" maxlength="25" class="input_18" style="width:350px;" id="txtName" name="txtName" keyenter /></td>
                    </tr>
                    <tr>
                        <td height="50">联系电话：</td>
                        <td><input type="text" maxlength="50" class="input_18" style="width:350px;" id="txtTelphone" name="txtTelphone" keyenter /></td>
                    </tr>
                    <tr>
                        <td height="50">电子邮件：</td>
                        <td><input type="text" maxlength="100" class="input_18" style="width:350px;" id="txtEmail" name="txtEmail" keyenter /></td>
                    </tr>
                    <tr>
                        <td height="30">&nbsp;</td>
                        <td valign="top">
                            <span class="font_gray_15" style="">请输入真实有效的电子邮件地址，否则您将无法使用找回密码功能</span>
                        </td>
                    </tr>
                    <tr>
                        <td height="50">机构/单位名称：</td>
                        <td><input type="text" maxlength="50" class="input_18" style="width:350px;" id="txtDomainName" name="txtDomainName" keyenter /></td>
                    </tr>
                    <tr>
                        <td height="50">验证码：</td>
                        <td>
                            <input type="text" maxlength="50" class="input_18" style="width:350px;" id="txtValidateCode" name="txtValidateCode" keyenter />
                            <img id="valiCode" style="cursor: pointer;" src="/Api/UserContext/GetValidateCode" alt="验证码" />
                        </td>
                    </tr>
                </table>
            </form>
    <table width="680" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td>&nbsp;</td>
        </tr>
    </table>
    <table width="680" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td><input name="btnLogin" type="button" class="btn_blue" id="btnLogin" value="注 册" onclick="register();" /></td>
        </tr>
    </table>
</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
    </tr>
</table>



